package com.x.compute.common.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 *
 * @author xuxin
 */
@Getter
@RequiredArgsConstructor
public enum YesOrNoEnum {

    /**
     * no
     */
    NO(0, false, "否"),
    /**
     * yes
     */
    YES(1, true, "是");

    public final Integer code;

    public final boolean flag;

    public final String chineseValue;

    public static String getChineseValue(int code) {
        for (YesOrNoEnum yesOrNoEnum : YesOrNoEnum.values()) {
            if (yesOrNoEnum.code == code) {
                return yesOrNoEnum.chineseValue;
            }
        }
        return null;
    }

    public static String getChineseValue(boolean flag) {
        if (flag) {
            return YES.chineseValue;
        }
        return NO.chineseValue;
    }

    public static int getCodeByFlag(boolean flag) {
        if (flag) {
            return YES.code;
        }
        return NO.code;
    }

    public static boolean getFlagByCode(int code) {
        for (YesOrNoEnum yesOrNoEnum : YesOrNoEnum.values()) {
            if (yesOrNoEnum.code == code) {
                return yesOrNoEnum.flag;
            }
        }
        return false;
    }

}
